package servlet_test;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletContext2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("我是GET");
        ServletContext context = getServletContext();
        System.out.println("我是context2");
        System.out.println(context);
        System.out.println("保存前获得key1的值："+context.getAttribute("key1"));
        context.setAttribute("key1","666");
        System.out.println("保存后获得key1的值："+context.getAttribute("key1"));
        System.out.println("保存后获得key1的值："+context.getAttribute("key1"));
    }
}
